<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <title>创建账号</title>
    <link rel="stylesheet" href="/static/weui/weui.min.css">
  </head>
  <style>
    body{
        background-color: var(--weui-BG-0);
    }
    h1 {
        display: block;
        font-size: 2em;
        margin-block-start: 0.67em;
        margin-block-end: 0.67em;
        margin-inline-start: 0px;
        margin-inline-end: 0px;
        font-weight: bold;
    }
    .page__desc {
        margin-top: 4px;
        color: var(--weui-FG-1);
        text-align: left;
        font-size: 14px;
    }
    .page__hd {
        padding: 40px;
    }
  </style>
  <body>
    <div class="weui-form">
        <div class="weui-form__text-area">
          <h2 class="weui-form__title">知鸟AI</h2>
          <div class="weui-form__desc">为用户创建知鸟AI后台账户，每个账户的使用费用为200/月，成为代理可获得至高百分之50的佣金。</div>
        </div>
        <div class="weui-form__control-area">
          <div class="weui-cells__group weui-cells__group_form">
            <div class="weui-cells__title">账户信息</div>
            <div class="weui-cells">
              <label for="js_input3" class="weui-cell weui-cell_active">
                <div class="weui-cell__hd"><span class="weui-label">登录账号</span></div>
                <div class="weui-cell__bd">
                    <input id="js_input3" class="weui-input" placeholder="建议填写手机号" type="number" pattern="[0-9]*">
                </div>
              </label>
            </div>
          </div>
        </div>
        <div class="weui-form__opr-area">
          <a role="button" aria-disabled="true" id="confirm-btn" class="weui-btn weui-btn_primary" href="javascript:" id="showTooltips" wah-hotarea="click">确定</a>
        </div>
        <div class="weui-form__extra-area">
          <div class="weui-footer">
            <p class="weui-footer__links">
              <a href="javascript:" class="weui-footer__link">知鸟AI</a>
            </p>
            <p class="weui-footer__text">Copyright © 2023 tinyask.cn</p>
          </div>
        </div>
      </div>
  </body>
  <script src='//res.wx.qq.com/open/js/jweixin-1.6.0.js'></script>
  <script>
    var config_str = '{$configJson|raw}';
    wx.config(JSON.parse(config_str));
    var confirmBtn = document.getElementById('confirm-btn');
    confirmBtn.addEventListener('click', function() {
        var phoneNumber = document.querySelector('.weui-input').value;
        if(!phoneNumber) {
            alert('输入手机号有误，请输入后重新提交');
            return false;
        }
        // 发起网络请求
        fetch('/index/user/createUserOrder', {
            method: 'POST',
            body: JSON.stringify({ username: phoneNumber }),
            headers: {
            'Content-Type': 'application/json'
            }
        }).then(function(response) {

            return response.json();
        }).then(function(response){
            var data = response['data'];
            if(response['code'] == 200){
                var options = JSON.parse(response['data']['optionJson']);
                options.success = function(){
                    alert('支付成功');
                    location.href="/index/user/showOrder?out_trade_no=" + response['data']['out_trade_no']
                }
                wx.chooseWXPay(options);
            }else{
                alert(response['msg']);
            }
        }).catch(function(error) {
            console.log(error);
            alert('网络错误');
        });
    });
  </script>


</html>
